package com.example.redislearn.example.pv.service.impl;

import com.example.redislearn.example.pv.service.UvStatisticService;
import org.redisson.Redisson;
import org.redisson.api.RAtomicLong;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

@Service
public class UvStatisticServiceImpl implements UvStatisticService {

    @Resource
    private Redisson redisson;


    @Override
    public Long increaseUv(String pageId) {
        RAtomicLong atomicLong = redisson.getAtomicLong(pageId);
        return atomicLong.incrementAndGet();
    }

    @Override
    public Long getUv(String pageId) {
        RAtomicLong atomicLong = redisson.getAtomicLong(pageId);
        return atomicLong.get();
    }
}
